@ECHO OFF
NET SESSION >nul 2>&1
IF "%ERRORLEVEL%"=="0" goto Adm
   echo ######## ########  ########   #######  ########  
   echo ##       ##     ## ##     ## ##     ## ##     ## 
   echo ##       ##     ## ##     ## ##     ## ##     ## 
   echo ######   ########  ########  ##     ## ########  
   echo ##       ##   ##   ##   ##   ##     ## ##   ##   
   echo ##       ##    ##  ##    ##  ##     ## ##    ##  
   echo ######## ##     ## ##     ##  #######  ##     ## 
   echo.
   echo.
   echo ####### ERROR: ADMINISTRATOR PRIVILEGES REQUIRED #########
   echo This script must be run as administrator to work properly!  
   echo If you're seeing this ERROR, then right-click on the file
   echo "install.bat" and select "Run As Administrator".
   echo ##########################################################
   echo.
   GOTO End
:Adm
ECHO Administrator PRIVILEGES Detected!

tasklist /FI "IMAGENAME eq HDDlifePro.exe" 2>NUL | find /I /N "HDDlifePro.exe">nul
IF "%ERRORLEVEL%"=="0" (
	echo.
	echo."Process HDDlifePro.exe is running"
	echo.
	echo."Trying to stop process."
	taskkill /F /IM HDDlifePro.exe
) ELSE (
	echo.Process HDDlifePro.exe is NOT running.
)

SET CURDIR=%~dp0

IF EXIST "%CommonProgramFiles(x86)%\BinarySense\hldasvc.exe" (
	SET CMF="%CommonProgramFiles(x86)%\BinarySense"
	) ELSE (
	SET CMF="%CommonProgramFiles%\BinarySense"
)

for /f "tokens=* delims=" %%P in (%CMF%) do (
    SET CMF=%%P
)

IF NOT EXIST "%CMF%\hldasvc.exe" (
	echo.
	echo."Error! Service file hldascv.exe not found in destination directory. Exiting"
	echo.
	GOTO End
)

echo.
echo."Stopping HDDlife HDD access service. Please wait..."
echo.
net stop "HDDlife HDD access service"
echo.

echo.Copying armaccess.dll...
copy /b /y "%CURDIR%armaccess.dll" "%CMF%\armaccess.dll">nul
IF "%ERRORLEVEL%"=="0" (
	echo."Copy success."
	echo.
	) ELSE (
		echo."Error while copying armaccess.dll."
		echo.
		GOTO End
)

echo.Replacing hldasvc.exe by the cracked one...
copy /b /y "%CURDIR%hldasvc.exe" "%CMF%\hldasvc.exe">nul
IF "%ERRORLEVEL%"=="0" (
	echo."Copy success."
	echo.
	) ELSE (
		echo."Error while copying hldascv.exe."
		echo.
		GOTO End
	)
fc /B "%CURDIR%hldasvc.exe" "%CMF%\hldasvc.exe">nul

IF NOT "%ERRORLEVEL%"=="0" goto err

echo.Service installation success.
echo.
echo.Restarting service. Please wait...
echo.
net start "HDDlife HDD access service"
echo.
echo.Cracked HDDlife service successfuly installed and running.
echo.
echo.Restarting HDDlife Pro. Please Wait...
start "" /B /D"%CURDIR%" HDDlifePro.exe
echo.
echo.Well done!
rem	del "%CURDIR%hldasvc.exe"
rem	del "%CURDIR%install.bat"
goto end

:err
echo.Installation failed :(
echo.Please, proceed to a manual installation like this:
echo.
echo.1. Open a console command and type:
echo.	sc stop "HDDlife HDD access service"
echo.2. Copy and overwrite armaccess.dll and hldascv.exe into Common File directory:
echo.		For x32: C:\Program Files\Common Files\BinarySense\
echo.		For x64: C:\Program Files (x86)\Common Files\BinarySense\
echo.3. with the same console command, type:
echo.		sc start "HDDlife HDD access service"
echo.


:End
echo.
PAUSE